package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author majun
 * @package sky-take-out
 * @date 2024/5/31 : 上午8:32
 */

@Mapper
public interface AddressBookMapper {

    /**
     * 查询当前登录用户的所有地址信息
     *
     * @return
     */
    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> list(Long userId);

    /**
     * 新增地址
     *
     * @param addressBook
     */
    @Insert("insert into address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) " +
            "values" +
            "(#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void add(AddressBook addressBook);

    /**
     * 查询默认地址
     *
     * @param addressBook
     * @return
     */
    @Select("select * from address_book where user_id=#{userId} AND is_default=#{isDefault}")
    AddressBook def(AddressBook addressBook);

    /**
     * 根据id查询地址
     *
     * @param id
     * @return
     */
    @Select("select * from address_book where id=#{id}")
    AddressBook getFromById(Long id);

    /**
     * 根据id删除地址
     *
     * @param id
     */
    @Delete("delete from address_book where id=#{id}")
    void detele(Long id);

    /**
     * 根据id修改地址
     *
     * @param addressBook
     */
    void put(AddressBook addressBook);
}
